package com.codebo.homiematchbackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codebo.homiematchbackend.mapper.TeamUserMapper;
import com.codebo.homiematchbackend.model.entity.TeamUser;
import com.codebo.homiematchbackend.model.entity.User;
import com.codebo.homiematchbackend.model.vo.UserVO;
import com.codebo.homiematchbackend.service.TeamUserService;
import com.codebo.homiematchbackend.service.UserService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 25912
 * @description 针对表【user_team(用户队伍关系表)】的数据库操作Service实现
 * @createDate 2025-09-15 13:46:22
 */
@Service
public class TeamUserServiceImpl extends ServiceImpl<TeamUserMapper, TeamUser>
        implements TeamUserService
{
    @Resource
    private UserService userService;

    @Override
    public List<UserVO> getTeamMemberVO(Long teamId)
    {
        QueryWrapper<TeamUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("team_id", teamId);

        List<TeamUser> listTeamUser = list(queryWrapper);

        return list(queryWrapper).stream().map(teamUser ->
        {
            User user = userService.getById(teamUser.getUserId());
            return userService.getUserVO(user);
        }).collect(Collectors.toList());

    }

    @Override
    public boolean isJoin(Long teamId, Long userId)
    {
        QueryWrapper<TeamUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("team_id", teamId).eq("user_id", userId);
        return count(queryWrapper) > 0;
    }
}




